package com.linshengjian.snowball.guard;

import com.linshengjian.snowball.guard.service.ILoginLabelHandler;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.util.HashMap;
import java.util.Map;

@ConfigurationProperties(prefix = "snowball.guard")
@Setter
@Getter
public class GuardProperties {

    public static class Token{
        /**
         * header 中使用的标签
         */
        private String header = "auth-token";
        /**
         * token的开头
         */
        private String tokenHead = "Bearer";
        /**
         * token 秘钥
         */
        private String secret;
        /**
         * 有效时间
         */
        private Long expiration = 7 * 24l * 60l *60l;

        public String getHeader() {
            return header;
        }

        public void setHeader(String header) {
            this.header = header;
        }

        public String getTokenHead() {
            return tokenHead;
        }

        public void setTokenHead(String tokenHead) {
            this.tokenHead = tokenHead;
        }

        public String getSecret() {
            return secret;
        }

        public void setSecret(String secret) {
            this.secret = secret;
        }

        public Long getExpiration() {
            return expiration;
        }

        public void setExpiration(Long expiration) {
            this.expiration = expiration;
        }
    }

    public static class VerifyCode{

        /**
         * 需要验证码验证的地址
         */
        private String verifyUrl = "";

        /**
         * 发送验证码的地址
         */
        private String send = "/verifyCode/send";
        /**
         * 验证验证码的地址
         */
        private String validate = "/verifyCode/validate";
        /**
         * 验证码的有效时长
         */
        private Long expiration = 15l * 60l;

//        /**
//         * 电话字段
//         */
//        private String phoneField = "verify-phone";
        /**
         * 验证码字段
         */
        private String codeField = "verify-code";
        /**
         * 验证 URL 字段
         */
        private String urlField = "verify-url";

        public String getSend() {
            return send;
        }

        public void setSend(String send) {
            this.send = send;
        }

        public String getValidate() {
            return validate;
        }

        public void setValidate(String validate) {
            this.validate = validate;
        }

        public Long getExpiration() {
            return expiration;
        }

        public void setExpiration(Long expiration) {
            this.expiration = expiration;
        }

        public String getVerifyUrl() {
            return verifyUrl;
        }

        public void setVerifyUrl(String verifyUrl) {
            this.verifyUrl = verifyUrl;
        }

        public String getCodeField() {
            return codeField;
        }

        public void setCodeField(String codeField) {
            this.codeField = codeField;
        }

        public String getUrlField() {
            return urlField;
        }

        public void setUrlField(String urlField) {
            this.urlField = urlField;
        }
    }

    public static class Login{

        public static class Url{
            /**
             * 登录地址
             */
            private String login = "/login";
            /**
             * 注销地址
             */
            private String logout = "/logout";

            public String getLogin() {
                return login;
            }

            public void setLogin(String login) {
                this.login = login;
            }

            public String getLogout() {
                return logout;
            }

            public void setLogout(String logout) {
                this.logout = logout;
            }
        }

        public static class Header{
            private String type = "login-type"; // 登录方式：密码登录、验证码登录、第三方登录
            private String label = "login-label"; // 登录标签

            public String getType() {
                return type;
            }

            public void setType(String type) {
                this.type = type;
            }

            public String getLabel() {
                return label;
            }

            public void setLabel(String label) {
                this.label = label;
            }
        }

        private Class<? extends PasswordEncoder> passwordStrategy = BCryptPasswordEncoder.class;

        private Url url = new Url();

        private Header header = new Header();

        /**
         * 登录方式
         */
        private Map<String, Class<? extends ILoginLabelHandler>> type = new HashMap<>();

        public Class<? extends PasswordEncoder> getPasswordStrategy() {
            return passwordStrategy;
        }

        public void setPasswordStrategy(Class<? extends PasswordEncoder> passwordStrategy) {
            this.passwordStrategy = passwordStrategy;
        }

        public Url getUrl() {
            return url;
        }

        public void setUrl(Url url) {
            this.url = url;
        }

        public Header getHeader() {
            return header;
        }

        public void setHeader(Header header) {
            this.header = header;
        }

        public Map<String, Class<? extends ILoginLabelHandler>> getType() {
            return type;
        }

        public void setType(Map<String, Class<? extends ILoginLabelHandler>> type) {
            this.type = type;
        }
    }

    private Token Token = new Token();

    /**
     * 不进行权限管理的路径
     */
    private String permit = "";

    /**
     * 验证码配置
     */
    private VerifyCode verifyCode = new VerifyCode();

    private Login login = new Login();

}
